<template>
  <div id="box">
    <div id="from" style="width: 600px;margin: auto">
      <h2 style="margin-left: 200px">修改放映信息</h2>

      <!--          'ShowFVO.s_day+" "+ShowFVO.s_hour'-->
      <el-form ref="form" :model="ShowFVO" label-width="80px">

        <el-form-item label="电影名称">
          <el-input v-model="ShowFVO.name" type="text" style="width: 200px" class="inp" disabled />
        </el-form-item>

        <el-form-item label="场次">
          <el-date-picker
            v-model="ShowFVO.s_day"
            type="datetime"
            value-format="yyyy年MM月dd日#HH:mm"
            placeholder="选择日期"
          />
        </el-form-item>

        <el-form-item label="放映厅">
          <el-input v-model="ShowFVO.s_playhall" type="text" style="width: 200px" class="inp" />
        </el-form-item>

        <el-form-item id="buttall">
          <el-button type="primary" @click="onSubmit(ShowFVO)">修改数据</el-button>
          <el-button id="butt2" @click="toMain">返回</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  name: 'Updatetimetable',
  data() {
    return {
      films: [{
        fnId: -1,
        fnName: ''
      }],
      values: {
        value: 0,
        label: '-请选择电影-'
      },

      ShowFVO: [
        {
          of_id: 1,
          name: '勇敢者游戏2：再战巅峰',
          s_day: '12月21日',
          s_hour: '8:00',
          s_playhall: 1
        }
      ]

    }
  },
  created() {
    this.initdata()// 初始化数据
  },

  methods: {
    initdata() {
      console.log('id')
      console.log(this.$route.params.id)
      var vm = this
      this.axios({
        url: 'http://localhost:81/api/show/querybyid?id=' + this.$route.params.id
      }).then(function(res) {
        if (res.data.success) {
          console.log(res.data.data)
          vm.ShowFVO = res.data.data
          //XX月XX日
          var t1 = res.data.data.s_day.replace('月', '-').replace('日', '')
          console.log(t1)
          var Y = new Date().getFullYear() + '-' + t1 + ' ' + vm.ShowFVO.s_hour
          console.log(Y)
          vm.ShowFVO.s_day = new Date(Y)
        }
      }).catch(function() {
        console.log('请求异常！')
      })
    },

    toMain() { // 添加电影的方法
      this.$router.push('/timetable')
    },
    onSubmit(movies) {
      console.log('submit---test')
      console.log(this.$route.params.id)
      console.log(movies)
      movies.s_playhall = parseInt(movies.s_playhall)
      var vm = this
      this.axios({
        url: 'http://localhost:81/api/show/update',
        params: {
          of_id: this.of_id,
          id: this.$route.params.id,
          name: movies.name,
          s_day: movies.s_day,
          s_playhall: movies.s_playhall
        }
      }).then(function(res) {
        if (res.data.success) {
          if (res.data.data > 0) {
            vm.$message({
              message: '修改成功',
              type: 'success',
              center: true
            })
            vm.$router.push('/timetable')
          }
        } else {
          vm.$message({
            message: '修改失败',
            type: 'error',
            center: true
          })
        }
      })
    }

  }
}
</script>

<style scoped>

</style>
